-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix infinite def write #316
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Kareem Farid <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider this slightl tweak to approach, outName
can be NULL (according to function docs), the lefFileOpen() will return the actual filename used (after resolving what it will be, when not provided via outName). So you can't do things like strlen(NULL).
The codebase doesn't really have NULL checks on failed mallocMagic() calls, so this mitigated to ASSERT and removes the whole what to do when it fails consideration the if() block implies.
I'm assuming the filename
contains the file extension (.def/.lef) as it is used directly with unlink()
as-is.
So this moves the block to be lower down around line 2986 of the original file.
filename1 = StrDup((char **)NULL, filename); // from original file line 2985
char *outName_part;
{ /* use the 'filename' given back from lefFileOpen() */
outName_part = mallocMagic(strlen(filename)+strlen("_part")+1);
ASSERT(outName_part, "outName_part");
strcpy(outName_part, filename);
char *cp = strrchr(outName_part, '.');
if (cp)
*cp = '\0'; /* remove extn */
strcat(outName_part, "_part");
}
defWriteHeader(def, f, scale, units); // from original file line 2987 (remove this comment)
@dlmiles : My problem with the original pull request is that I still don't understand the nature of the infinite loop and I don't see how the code change fixes it, and I don't understand the need to change the file name being written out. This is mostly do to me having limited time to check and test code changes. |
Understand, just trying to help out with the code review aspect to point out I am not affected by the problem this commit is trying to address. @kareefardi is the infinite loop an internal magic infinite loop? Or an issue with external tooling seeing or not seeing well formed files with the appropriate file extension? Is there an example command sequence to run with project files to demonstrate the original problem? |
@dlmiles @RTimothyEdwards I was able to isolate the problem to it being caused by calling |
This tries a re-open of the given filename "spm.def" and this is a hit and is successful, so it returns a handle as-is. When the given filename is "spm" I guess it can't see an extension to try to match, so this is doesn't try this "optimization" |
Order of events:
The optimization (if that is a good term) in the Previously (before this PR) outName is the same value to all calls to lefFileOpen(), which then derives the By modifying outName to append |
I think
.def_part
is resolved to.def
resulting in infinite write behavior. This renames the partial file.._part.def
avoiding the infinite loop while writing def.I am not sure however if
freeMagic(outName_part)
is called in all the correct places.